package com.demo.dto;

import com.demo.enums.BizExceptionEnum;

/**
 * web控制器层返回的json数据的默认格式对应的Java类
 * @author dj
 *
 * @param <T>
 */
public class CommonResult<T> {
	private boolean flag = false;		//请求是否成功
	private String errorCode = "-1";	//响应错误码
	private String errorMsg = "";		//响应错误信息
	private T data;						//响应结果
	
	public CommonResult() {
		super();
	}
	
	public CommonResult(T data) {
		super();
		setData(data);
	}

	public CommonResult(String errorCode, String errorMsg) {
		super();
		this.errorCode = errorCode;
		this.errorMsg = errorMsg;
	}

	public CommonResult(BizExceptionEnum bizException) {
		super();
		setBizException(bizException);
	}
	
	public void setBizException(BizExceptionEnum bizException){
		this.errorCode = bizException.getCode();
		this.errorMsg = bizException.getMsg();
	}
	
	public void setFlag(boolean flag) {
		this.flag = flag;
	}
	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}
	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}
	public void setData(T data) {
		this.flag = true;
		this.data = data;
	}
	public boolean isFlag() {
		return flag;
	}
	public String getErrorCode() {
		return errorCode;
	}
	public String getErrorMsg() {
		return errorMsg;
	}
	public T getData() {
		return data;
	}
	
}
